﻿using DevExpress.Data;
using DevExpress.XtraGrid;
using DXApplicationTangche.UC.抖音出入库.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音订单一览 : DevExpress.XtraEditors.XtraForm
    {
        public Form抖音订单一览()
        {
            InitializeComponent();
        }
        private void 刷新(String start, String end)
        {
            List<DouyinOrderViewDTO> douyinOrderViewDTOs = 抖音订单Service.getDouyinOrderViewByDataStr(start,end);
            this.gridControl抖音订单一览.DataSource = douyinOrderViewDTOs;
            this.bandedGridView1.ExpandAllGroups();
            this.bandedGridView1.GroupSummary.Clear();
        }

        private void dateTimePicker开始时间_ValueChanged(object sender, EventArgs e)
        {
            this.刷新(this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd"),
                this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd"));
        }

        private void dateTimePicker结束时间_ValueChanged(object sender, EventArgs e)
        {
            this.刷新(this.dateTimePicker开始时间.Value.ToString("yyyy-MM-dd"),
                this.dateTimePicker结束时间.Value.ToString("yyyy-MM-dd"));
        }

        private void bandedGridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            try
            {
                if (e.RowHandle >= 0)
                {
                    DouyinOrderViewDTO douyinOrderViewDTO = (DouyinOrderViewDTO)bandedGridView1.GetRow(e.RowHandle);
                    if (douyinOrderViewDTO.goodsReturn)
                    {
                        if (e.Column.Name.Equals("gridColumn退款是否收到货"))
                        {
                            e.Appearance.BackColor = Color.DeepPink;
                            //e.Appearance.ForeColor = Color.White;
                        }
                    }
                    if (douyinOrderViewDTO.saleFund)
                    {
                        if (e.Column.Name.Equals("gridColumn是否收款"))
                        {
                            e.Appearance.BackColor = Color.Orange;
                            //e.Appearance.ForeColor = Color.White;
                        }
                    }
                    if (douyinOrderViewDTO.returnFund)
                    {
                        if (e.Column.Name.Equals("gridColumn是否退款"))
                        {
                            e.Appearance.BackColor = Color.Blue;
                            //e.Appearance.ForeColor = Color.White;
                        }
                    }
                }
            }
            catch { }
        }

        private void bandedGridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            if (e.Column.Name.Equals("gridColumn订单完成时间"))
            {
                if ("0".Equals(e.DisplayText))
                {
                    e.DisplayText = "";
                }
            }
            if (e.Column.Name.Equals("gridColumn发起售后时间"))
            {
                if ("0".Equals(e.DisplayText))
                {
                    e.DisplayText = "";
                }
            }
            if (e.Column.Name.Equals("gridColumn发运时间"))
            {
                if ("0".Equals(e.DisplayText))
                {
                    e.DisplayText = "";
                }
            }
        }

        private void simpleButton导出抖音订单_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出抖音订单";
            fileDialog.Filter = "Excel文件(*.xlsx)|*.xlsx";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                //保存销售收款单、退款退货单、退款未退货单
                this.bandedGridView1.ExportToXlsx(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("文件已保存至" + fileDialog.FileName, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
    }
}
